package rpcsuport

import (
	"log"
	"net"
	"net/rpc"
	"net/rpc/jsonrpc"
)

func ServeRpc(host string,service interface{}) error {
   rpc.Register(service)

	listener,err:=net.Listen("tcp",host)
	if err!=nil {
		return err
	}

	for{
		conn,err:=listener.Accept()
		if err!=nil{
			log.Printf("accept error:%s",err)
			continue
		}
		go jsonrpc.ServeConn(conn)
	}
	return nil
}

func NewClient(host string) (*rpc.Client,error)  {
	conn,err:=net.Dial("tcp",host)
	if err!=nil {
		return nil,err
	}
	client:=jsonrpc.NewClient(conn)
	return client,nil
}





